{% load static %}
<!--
  ~ Copyright 2024-2034 the original author or authors.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  ~
  -->

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8"/>
        <link rel="apple-touch-icon" sizes="76x76" href="{% static 'assets/img/favicon.ico' %}">
        <link rel="icon" type="image/png" href="{% static 'assets/img/favicon.ico' %}">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <title>AI sign in</title>
        <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no' name='viewport'/>
        <!-- Google Font -->
        <link href="https://fonts.googleapis.com/css?family=Nunito:300,300i,400,600,800" rel="stylesheet">
        <!-- Font Awesome Icons -->
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
        <!-- Main CSS -->
        <link href="{% static 'assets/css/main.css' %}" rel="stylesheet"/>
        <!-- Animation CSS -->
        <link href="{% static 'assets/css/vendor/aos.css' %} " rel="stylesheet"/>
    </head>

    <body>


    <!--------------------------------------
    NAVBAR
    --------------------------------------->
    <nav class="topnav navbar navbar-expand-lg navbar-dark bg-primary fixed-top">
    <div class="container-fluid">
        <a class="navbar-brand d-sm-block d-md-none" href="#"><i class="fas fa-anchor mr-2"></i><strong>AI UI</strong> Kit</a>
        <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarColor02" aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse" id="navbarColor02" style="">
            <ul class="navbar-nav mr-auto d-flex align-items-center">
                <li class="nav-item">
                <a class="nav-link" href="/">Intro</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Examples </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="./landing.html">Home Landing</a>
                    <a class="dropdown-item" href="./login.html">User Login</a>
                    <a class="dropdown-item" href="./blog.html">Blog Index</a>
                    <a class="dropdown-item" href="./page.html">Sample Page</a>
                </div>
                </li>
                <li class="nav-item">
                <a class="nav-link" href="./docs.html">Docs</a>
                </li>
            </ul>
        </div>
    </div>
    </nav>
    <!-- End Navbar -->

    <!-- Main -->
    <div class="d-md-flex h-md-100 align-items-center">
        <div class="col-md-6 p-0 bg-indigo h-md-100">
            <div class="text-white d-md-flex align-items-center h-100 p-5 text-center justify-content-center">
                <div class="logoarea pt-5 pb-5">
                    <p>
                        <i class="fa fa-anchor fa-3x"></i>
                    </p>
                    <h1 class="mb-0 mt-3 display-4">Artificial Intelligence</h1>
                    <h5 class="mb-4 font-weight-light">AI UI Kit with <i class="fab fa-sass fa-2x text-cyan"></i></h5>
                    <a class="btn btn-outline-white btn-lg btn-round" href="https://xinxinji.cn" target="_blank" data-toggle="modal" data-target="#modal_newsletter">Big Data <a href="https://xinxinji.cn" class="downloadzip" class="hidden"></a>
                    </a>
                </div>
            </div>
        </div>
        <div class="col-md-6 p-0 bg-white h-md-100 loginarea">
            <div class="d-md-flex align-items-center h-md-100 p-5 justify-content-center">
                <form name="login-form" class="border rounded p-5" method="post"  onsubmit="return onlogin()">
                    <h3 class="mb-4 text-center">Sign In</h3>
                    <div class="form-group">
                        <input name="userName" type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="UserName" autocomplete="off" required="required" maxlength="52">
                    </div>
                    <div class="form-group">
                        <input name="password" type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" autocomplete="off" required="required" maxlength="32">
                    </div>
                    <div class="form-group">
                        <input style="width: 50%;display: inline-block;" name="validateCode" type="text" class="form-control" placeholder="验证码" autocomplete="off" required="required" maxlength="6"><img class="verify-code" data-img="verify-code" style="width: 40%; float: right;" src="../user/verifyCodeImage">
                    </div>
                    <div class="form-group form-check">
                        <input type="checkbox" class="form-check-input" id="exampleCheck1">
                        <label class="form-check-label small text-muted" for="exampleCheck1">Remember me</label>
                    </div>
                    <button type="submit" class="btn btn-success btn-round btn-block shadow-sm">Sign in</button>
                    <small class="d-block mt-4 text-center"><a class="text-gray" href="#">Forgot your password?</a></small>
                </form>
            </div>
        </div>
    </div>
    <!-- End Main -->

    <!------------------------------------------
    DEMO MODAL & DONATE BUTTON ONLY - DON'T COPY
    ------------------------------------------->
    <div class="modal fade" id="modal_newsletter" tabindex="-1" role="dialog" aria-labelledby="modal_newsletter" aria-hidden="true">
        <div class="modal-dialog shadow-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <div class="d-flex align-items-center justify-content-center">
                        <em class="text-muted mr-2">Share this freebie:</em>
                        <!-- Share Facebook -->
                        <span class="c-pointer iconbox iconsmall rounded-circle bg-secondary text-white mr-1" data-sharer="facebook" data-url="https://www.wowthemes.net/anchor-free-bootstrap-ui-kit/"><i class="fab fa-facebook-f"></i></span>
                        <!-- Share Twitter -->
                        <span class="c-pointer iconbox iconsmall rounded-circle bg-info text-white mr-1" data-sharer="twitter" data-title="Download Anchor - Free Bootstrap 4.1.x UI Kit with Sass!" data-hashtags="bootstrap,free" data-url="https://www.wowthemes.net/anchor-free-bootstrap-ui-kit/"><i class="fab fa-twitter"></i></span>
                        <!-- Share Google+ -->
                        <span class="c-pointer iconbox iconsmall rounded-circle bg-danger text-white mr-1" data-sharer="googleplus" data-url="https://www.wowthemes.net/anchor-free-bootstrap-ui-kit/"><i class="fab fa-google"></i></span>
                        <!-- Share E-mail -->
                        <span class="c-pointer iconbox iconsmall rounded-circle bg-purple text-white mr-1" data-sharer="email" data-title="Bootstrap KIT Url" data-url="https://www.wowthemes.net/anchor-free-bootstrap-ui-kit/" data-subject="Download Anchor - Free Bootstrap 4.1.x UI Kit with Sass!" data-to="some@email.com"><i class="fas fa-envelope"></i></span>
                        <!-- Sharingbutton Pinterest -->
                        <span class="c-pointer iconbox iconsmall rounded-circle bg-danger text-white mr-1" data-sharer="pinterest" data-url="https://www.wowthemes.net/anchor-free-bootstrap-ui-kit/"><i class="fab fa-pinterest"></i></span>
                    </div>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="text-center mb-3">
                        <img src="{% static 'assets/img/favicon.ico'%}">
                    </div>
                    <h6 class="text-center font-weight-light ">Thanks for downloading AI Bootstrap UI Kit!</h6>
                    <h5 class="text-center mb-4">We'll e-mail you when a new version arrives! *</h5>
                    <form id="newsletter-form" action="https://www.themepush.com/sendy/subscribe" method="POST" accept-charset="utf-8">
                        <div class="d-none">
                            <label for="hp">HP</label>
                            <br>
                            <input type="text" name="hp" id="hp">
                        </div>
                        <div class="row justify-content-center align-items-center">
                            <div class="col-md-6">
                                <div class="form-group has-icon-left form-control-name">
                                    <label class="sr-only" for="inputName">Your name</label>
                                    <input type="text" name="name" id="name" required="" pattern="[A-Za-z\s]+" class="form-control" placeholder="Name">
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group has-icon-left form-control-email">
                                    <label class="sr-only" for="inputEmail">Email address</label>
                                    <input type="email" name="email" id="email" required="" class="form-control" placeholder="E-mail">
                                </div>
                            </div>
                            <input type="hidden" name="list" value="CVN62nDKE0qTf4XLs8J9iQ" checked="checked">
                            <div class="col-md-12 mb-3">
                                <input type="hidden" name="subform" value="yes">
                                <input onclick="requiredConsent()" class="btn btn-success btn-block shadow-sm" value="Send me updates & more freebies" type="submit" name="submit" id="submit">
                            </div>
                            <div class="col-md-12 mb-3 text-center">
                                <small class="d-block" style="color:#ccc;font-style:italic;line-height:1.4;">* This is a newsletter managed by WowThemes, the item author. It is the only way we can reach you out when a new version is released, so, please, subscribe!</small>
                            </div>
                        </div>
                        <div class="row justify-content-center d-none mt-3">
                            <label class="c-input c-checkbox small">
                            <input type="checkbox" name="gdpr" id="gdpr" checked="checked">
                            <span class="c-indicator"></span> I agree to the <a target="_blank" href="https://www.wowthemes.net/privacy-policy/#newsletter-subscription-forms">privacy policy</a>. </label>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div style="position:fixed; bottom:20px;left:20px;">
        <a href="https://xinxinji.cn" target="_blank"><img class="rounded-circle shadow-lg" src="{% static 'assets/img/demo/coffee.png' %}" width="70" data-toggle="tooltip" data-placement="top" title="" data-original-title="Buy me a coffee!"></a>
    </div>
    <!--------------------------------------
    END DEMO MODAL & DONATE BUTTON
    --------------------------------------->

    <!--------------------------------------
    JAVASCRIPTS
    --------------------------------------->
    <script src="{% static 'assets/js/vendor/jquery.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'js/jquery.validate.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'js/sm2.js' %}" type="text/javascript"></script>
    <script src="{% static 'assets/js/vendor/popper.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'assets/js/vendor/bootstrap.min.js' %}" type="text/javascript"></script>
    <script src="{% static 'assets/js/functions.js' %}" type="text/javascript"></script>

    <!-- Animation -->
    <script src="{% static 'assets/js/vendor/aos.js' %}" type="text/javascript"></script>

    <noscript>
        <style>
            *[data-aos] {
                display: block !important;
                opacity: 1 !important;
                visibility: visible !important;
            }
        </style>
    </noscript>

    <script type="text/javascript">
        var cipherMode = 0; // 0: C1C2C3,1:C1C3C2
        var keys = {};
        AOS.init({
            duration: 700
        });
        <!-- Disable animation on less than 1200px, change value if you like -->
        AOS.init({
          disable: function () {
            var maxWidth = 1200;
            return window.innerWidth < maxWidth;
          }
        });
        window.getParams = function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
            var context = "";
            if (r != null) {
                context = decodeURIComponent(r[2]);
            }
            reg = null;
            r = null;
            return context == null || context == "" || context == "undefined" ? "" : context;
        };
        window.uuid = function() {
            var s = [];
            var hexDigits = "0123456789abcdef";
            for (var i = 0; i < 32; i++) {
                s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
            }
            s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
            s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
            s[8] = s[13] = s[18] = s[23];
            var uuid = s.join("");
            return uuid;
        };
        window.hash = function (value) {
            var hash = 0;
            for (var i =0; i < value.length; i++) {
                var v = value[i].charCodeAt(0);
                hash += 2 << v;
            }
            return hash;
        };
        (function() {

    /**
            var loginBtn = document.getElementsByName("login-btn")[0];
            loginBtn.addEventListener("click", function(e) {
                var inputs = document.querySelectorAll("input");
                loginBtn.setAttribute("disabled", "disabled");
                var url = '../../../prod-api/cxcSheinAuthorize/callback';
                var param = {account:inputs[0].value, password:inputs[1].value, redirectUrl:window.atob(getParams("redirectUrl")),
                        state:getParams("state"), appid:getParams("appid"), tempToken : window.uuid(), t: Date.now()};
                if (param.account == '' || param.password == '') {
                    alert("账号或密码不能为空！");
                    loginBtn.removeAttribute("disabled");
                    return;
                }
                var jsonString = JSON.stringify({account: window.hash(param.account), password: window.hash(param.password), t : param.t});
                var xhr = new XMLHttpRequest();
                var urlParam = "?appid=" + param.appid + "&state=" + param.state + "&tempToken=" + param.tempToken;
                //2、建立连接，要求异步响应
                xhr.open('GET', url + urlParam, true);
                //3、监听异步响应状态
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === XMLHttpRequest.DONE) {
                        loginBtn.removeAttribute("disabled");
                        var result = JSON.parse(xhr.responseText);
                        alert(result.msg);
                    }
                };
                // 4、发送请求
                xhr.send(jsonString)
            });
            */

             $("img[data-img=verify-code]").click(function(e){
                //var url = "../user/verifyCodeImage?t=" + Math.random();
                url = "../user/verifyCodeImage?t=" + Date.now();
                $(this).attr("src", url);
            });
        })();

        $.get('../user/publickey', function(res) {
            keys = res;
        });

        function onlogin() {
            var form = $("form[name=login-form]").serialize();
            var password = $("form[name=login-form] input[name=password]").val();
            var encryptpwd = sm2.doEncrypt(password, keys.publickey, cipherMode);
            form = form.replace("password=" + password, "password=" + encryptpwd);
            $.ajax({
                url:'../user/login',
                method:"POST",
                data:form,
                success:function(res) {
                    if (res.code == 200) {
                        window.location.href = "/";
                    } else {
                        alert(res.msg);
                    }
                },
                error:function(response) {
                    console.error(response);
                }   
            });
            return false;
        }
    </script>

    </body>
</html>